package com.zzyl.controller;

import cn.hutool.json.JSONObject;
import com.aliyun.iot20180120.models.BatchUpdateDeviceNicknameRequest;
import com.aliyun.iot20180120.models.DeleteDeviceRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.ThingModelPublishedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Description DeviceController
 * @Author Bafeii7
 * @Date 2025-05-19 16:01
 */
@RestController
@RequestMapping("/iot")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> syncDeviceList() {
        List<ProductVo> productList = deviceService.allProductList();
        return success(productList);
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return success();
    }

    @GetMapping("pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return success(deviceVo);
    }


    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<ThingModelPublishedVo> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        ThingModelPublishedVo thingModelJson = deviceService.queryThingModelPublished(request);
        return success(thingModelJson);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<DevicePropertyStatusVo> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        DevicePropertyStatusVo list = deviceService.queryDevicePropertyStatus(request);
        return success(list);
    }


    @PostMapping("/UpdateDevice")
    public ResponseResult batchUpdateDeviceNickname(@RequestBody DeviceDto deviceDto){
        deviceService.batchUpdateDeviceNickname(deviceDto);
        return success();
    }


    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest request){
        deviceService.deleteDevice(request);
        return success();
    }
}
